package com.cheer.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

/**
 * @author cheer
 */
@Repository
public class AccessTokenCacheDao {

    private static final String ACCESS_TOKEN_KEY = "access_token";

    private static final String TICKET_KEY = "ticket";

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public String getAccessToken() {
        return stringRedisTemplate.opsForValue().get(ACCESS_TOKEN_KEY);
    }

    public void setAccessToken(String accessToken) {
        stringRedisTemplate.opsForValue().set(ACCESS_TOKEN_KEY, accessToken,
                1, TimeUnit.HOURS);
    }

    public String getTicket() {
        return stringRedisTemplate.opsForValue().get(TICKET_KEY);
    }

    public void setTicket(String ticket) {
        stringRedisTemplate.opsForValue().set(TICKET_KEY, ticket, 1, TimeUnit.HOURS);
    }

}
